package com.bjshiwei.zhengu.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import java.util.List;

/**
 * 作者：Administrator on 2017/2/9 0009 18:09
 * 邮箱：sanjins@126.com
 */


public abstract class MyBaseAdapter2<T> extends BaseAdapter{

    private List<T> mDatas;
    private LayoutInflater layoutInflater;
    public MyBaseAdapter2(List<T> datas, Context context){
        mDatas = datas;
        layoutInflater = LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return mDatas==null?0:mDatas.size();
    }

    @Override
    public Object getItem(int i) {
        return mDatas.get(i);
    }

    public LayoutInflater getLayoutInflater(){
        return layoutInflater;
    }
    @Override
    public long getItemId(int i) {
        return i;
    }

    public abstract View getView(int i, View view, ViewGroup viewGroup);

    /**
     * clear
     */

    public void clear(){
        mDatas.clear();
        notifyDataSetChanged();
    }

    /**
     * 增加数据源
     */

    public void addItem(List<T> item){
        mDatas.addAll(item);
        notifyDataSetChanged();
    }

    /**
     * 删除选中数据源
     */

    public void delItem(int position){
        mDatas.remove(position);
        notifyDataSetChanged();
    }

    /**
     * 指定位置添加数据源
     */
    public void addPosition(int position,T item){
        mDatas.add(position,item);
        notifyDataSetChanged();
    }
}
